<template>
  <div class="login">
    <div class="icon">
      <span class="fuhao">
        <i class="iconfont icon-yinlebofangxuanlv"></i>
      </span>
    </div>

    <!-- 登录框 -->
    <main>
      <div class="loginkuang">
        <van-cell-group>
          <van-field
            class="phone"
            v-model="phone"
            left-icon="user-o"
            placeholder="请输入手机号"
            right-icon="warning-o"
            label-width="60px"
            clearable
          />
          <van-field
            class="paw"
            v-model="password"
            type="password"
            left-icon="bag-o"
            placeholder="请输入密码"
            right-icon="warning-o"
            label-width="60px"
            clearable
          />
        </van-cell-group>
        <div class="btn">
          <button class="btnlogin" @click="clicklogin">登录</button>
          <!-- <button class="btnregister" @click="clickregister">注册</button> -->
          <span class="nowregister" @click="clickregister">现在注册&nbsp;></span>
        </div>
      </div>
    </main>
  </div>
</template>

<script>
import backTitle from "../../components/back";
import send from "../../navshow";

export default {
  // inject:['reload'],
  data() {
    return {
      phone: "", //用户名
      password: "" //密码
    };
  },
  created() {
    // 隐藏导航栏
    send.$emit("tab-show", false);
    // 隐藏播放器
    this.$store.commit("showplayer", false);
  },
  methods: {
    // 登录
    clicklogin() {
      if (this.phone == "") {
        this.$toast("请输入手机号");
      } else if (this.password == "") {
        this.$toast("请输入密码");
      } else {
        var url =
          "http://localhost:3000/login/cellphone?phone=" +
          this.phone +
          "&password=" +
          this.password;
        this.axios
          .get(url)
          .then(res => {
            if (res.status == 200) {
              sessionStorage.setItem("id", res.data.account.id);
              this.$router.replace({
                path: "/login/emptypage",
                name: "emptypage",
              }); //登录成功跳转到推荐页
            }
          })
          .catch(err => {
            this.err = "账号或密码错误";
            this.$toast("账号或密码输入错误，请重新输入！");
          });
      }
    },

    //   跳转到注册页面
    clickregister() {
      this.$router.push("/login/register");
    }
  },
  components: {
    backTitle
  }
};
</script>

<style>
.login {
  width: 100vw;
  height: 100vh;
  position: relative;
  background-color: #eeeeee;
}

/* 图标 */
.login .icon {
  width: 100%;
  height: 45vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-image: url("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1843625595,2022074812&fm=26&gp=0.jpg");
  background-size: 100% 110%;
}

.login .fuhao {
  display: block;
  width: 100px;
  height: 100px;
  text-align: center;
  border-radius: 50px;
  background: #c0c0c0;
  box-shadow: 20px 20px 60px #686868, -20px -20px 60px #ffffff;
}

.login .fuhao i {
  font-size: 70px;
}

/* 登录框 */
.login .loginkuang {
  width: 80vw;
  margin: 20px auto 10px;
}

.login .phone,
.login .paw {
  padding-top: 20px;
  border-bottom: 1px solid lightgray;
}

.login .van-cell {
  background-color: #eeeeee;
}

.login .loginkuang .btn {
  margin: 20px auto;
  display: flex;
  flex-direction: column;
}

.login .loginkuang button {
  width: 50vw;
  height: 40px;
  margin: 5px auto 5px;
  color: white;
  font-size: 18px;
  border: 0;
  border-radius: 50px;
  background: #231F20;
}

.login .nowregister {
  color: gray;
  margin-top: 20px;
}

.login input {
  font-size: 14px;
}
</style>